package cn.com.ddapp.ddm.ui;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.LatLngBounds;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.adapter.NearstoreAdpter;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.base.BaseApplication;
import cn.com.ddapp.ddm.bean.NearStoreBean;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.widget.pulltorefresh.PullToRefreshLayout;
import cn.com.ddapp.ddm.widget.pulltorefresh.pullableview.PullableListView;
import okhttp3.Call;


/**
 * Created by Administrator on 2016/7/29 0029.
 */
public class NearStoreDetailsActivity extends Activity implements AMap.OnMapLoadedListener,AMap.OnMarkerDragListener {

    @BindView(R.id.near_mapview)
    MapView mMapView;
    AMap aMap;
    Unbinder unbinder;
    private LocationSource.OnLocationChangedListener mListener;
    private AMapLocationClient mlocationClient;
    private AMapLocationClientOption mLocationOption;
    private double latitude;
    private double longitude;
    LatLng point;
    private String name;
    private LatLng latlng;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.near_detailsmap);
//        initView();
        unbinder= ButterKnife.bind(this);
        latitude=getIntent().getDoubleExtra("lat",22.733767);
        longitude=getIntent().getDoubleExtra("lng",113.831474);
        name=getIntent().getStringExtra("whName");

        point=new LatLng(latitude,longitude);
        latlng = new LatLng(latitude, longitude);
//        Log.i("aaa","-point-"+latitude+"--"+longitude);
//        try{
            mMapView.onCreate(savedInstanceState);
//        }catch (Throwable e){
//            Toast.makeText(this,"该手机不支持高德地图",Toast.LENGTH_SHORT).show();
//            finish();
//            return;
//        }

        if (aMap == null) {
            aMap = mMapView.getMap();
            initData(point);
        }
    }

    private void initData(LatLng Point) {
//        wh_map_title.setText(name);
        aMap.setOnMapLoadedListener(this);
        drawMarkerOnMap(Point,name);
    }

    private void drawMarkerOnMap(LatLng Point, String name) {
        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(Point);
        markerOption.draggable(true);
        markerOption.icon(BitmapDescriptorFactory.fromResource(R.mipmap.map));
        markerOption.setFlat(true);// 将Marker设置为贴地显示，可以双指下拉看效果
        markerOption.title("亿指商城").snippet(name);

        Marker marker = aMap.addMarker(markerOption);
        marker.setRotateAngle(30);
        marker.showInfoWindow();
    }

	@OnClick({R.id.share_back})
	public void onClick(View v) {
		switch (v.getId()) {
            case R.id.share_back:
                finish();
                break;

		}
	}




    @Override
    public void onMapLoaded() {
        LatLngBounds bounds = new LatLngBounds.Builder().include(latlng).include(point)
                .build();
        aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 150));
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
        unbinder.unbind();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mMapView.onSaveInstanceState(outState);
    }

    @Override
    public void onMarkerDragStart(Marker marker) {

    }

    @Override
    public void onMarkerDrag(Marker marker) {

    }

    @Override
    public void onMarkerDragEnd(Marker marker) {

    }
}
